#ifndef __SVC_THREADPOOL_H_
#define __SVC_THREADPOOL_H_

#ifdef __cplusplus
extern "C"
{
#endif

#include <types.h>
#include <dlist.h>
#include <evtloop.h>

struct svc__work
{
    struct list_head    wq;
    ev_loop_t          *loop;
    void (*work)(struct svc__work *w);
    void (*done)(struct svc__work *w, int status);
};
void svc__work_submit(ev_loop_t *loop,
                      struct svc__work *w,
                      void (*work)(struct svc__work *w),
                      void (*done)(struct svc__work *w, int status));
void svc__work_done(svc_async_t *handle);

typedef struct svc_work svc_work_t;
typedef void (*svc_work_cb_t)(svc_work_t *w);
typedef void (*svc_after_work_cb_t)(svc_work_t *w, int status);
struct svc_work
{
    struct svc__work    work_req;
    ev_loop_t          *loop;

    svc_work_cb_t       work_cb;
    svc_after_work_cb_t after_work_cb;
    void               *data;
};

int svc_queue_work(ev_loop_t *loop, svc_work_t *w, svc_work_cb_t work_cb,
                   svc_after_work_cb_t after_work_cb);
int svc_cancel(ev_loop_t *loop, svc_work_t *w);

void uv__threadpool_cleanup(void);
#ifdef __cplusplus
}
#endif
#endif
